package cn.mw.cmdb.virtualization.controller;

import cn.mw.cmdb.virtualization.dto.VirtualizationStorageDto;
import cn.mw.cmdb.virtualization.dto.VirtualizationTreeDto;
import cn.mw.cmdb.virtualization.dto.unicloud.UniCloudVsWitchDto;
import cn.mw.cmdb.virtualization.param.VirtualizationParam;
import cn.mw.cmdb.virtualization.service.MwVirtualizationService;
import cn.mw.microMonitorCommon.api.common.BaseApiService;
import cn.mw.microMonitorCommon.api.common.ResponseBase;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author gengjb
 */
@RequestMapping("/virtualization")
@Controller
@Tag(name = "虚拟化管理")
@Slf4j
public class MwVirtualizationController extends BaseApiService {

    private MwVirtualizationService virtuelizetionService;

    @Autowired
    public MwVirtualizationController(MwVirtualizationService virtuelizetionService) {
        this.virtuelizetionService = virtuelizetionService;
    }

    @PostMapping("/testInstanceRelationData")
    @ResponseBody
    @Operation(summary = "测试关联")
    public ResponseBase instanceRelationData(@RequestBody VirtualizationParam param) {
        virtuelizetionService.instanceRelationData(param);
        return setResultSuccess();
    }



    @PostMapping("/getVirtualizationTree")
    @ResponseBody
    @Operation(summary = "获取虚拟化树结构数据")
    public ResponseBase<List<VirtualizationTreeDto>> getVirtualizationTreeInfo(@RequestBody VirtualizationParam param) throws Exception {
        List<VirtualizationTreeDto> virtualizationTree = virtuelizetionService.getVirtualizationTree(param);
        return setResultSuccess(virtualizationTree);
    }

    @PostMapping("/getVirtualizationStorage")
    @ResponseBody
    @Operation(summary = "获取虚拟化存储信息")
    public ResponseBase<List<VirtualizationStorageDto>> getVirtualizationStorage(@RequestBody VirtualizationParam param) throws Exception {
        Page page = virtuelizetionService.getVirtualizationStorageInfo(param);
        return setResultSuccess(page);
    }

    @PostMapping("/getVirtualizationListInfo")
    @ResponseBody
    @Operation(summary = "获取虚拟化列表展示信息")
    public ResponseBase getVirtualizationListInfo(@RequestBody VirtualizationParam param) throws Exception {
        Object data = virtuelizetionService.getVirtualizationBasicInfo(param);
        return setResultSuccess(data);
    }

    @PostMapping("/syncVirtualizationData")
    @ResponseBody
    @Operation(summary = "同步虚拟化数据")
    public ResponseBase syncVirtualizationData(@RequestBody VirtualizationParam param) throws Exception {
        virtuelizetionService.syncVirtualizationData(param);
        return setResultSuccess();
    }

    @PostMapping("/getUniCloudVsWitch")
    @ResponseBody
    @Operation(summary = "获取虚拟交换机")
    public ResponseBase getUniCloudVsWitch(@RequestBody VirtualizationParam param) throws Exception {
        Page page = virtuelizetionService.getUniCloudVsWitchInfo(param);
        return setResultSuccess(page);
    }
}
